import wx
import os
import wx.grid


class Task:
    def __init__(self) -> None:

        self.name = "aaa"


def fontstyle(f):
    font = wx.Font(16, wx.DECORATIVE, style=wx.NORMAL, weight=wx.BOLD)
    f.SetForegroundColour("White")
    f.SetFont(font)


class DialogControl(wx.Dialog):
    account = None
    password = None

    def __init__(self, *args, **kwargs):
        super(DialogControl, self).__init__(*args, **kwargs)
        # 初始化窗口UI
        self.init_ui()

    def init_ui(self):
        # 账号
        img = wx.Bitmap("img/03_bg.png")
        self.SetSize(img.Width, img.Height)
        bitmap = wx.StaticBitmap(self, -1, img)
        # to_bmp_image = wx.Bitmap(
        #     "img/03_bg.png", wx.BITMAP_TYPE_ANY)
        # # .Resize((1280, 800), (0, 0))
        # # to_bmp_image = to_bmp_image.Scale(
        # #     1280, 800, wx.IMAGE_QUALITY_HIGH).ConvertToBitmap()
        # bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
        images = wx.Bitmap("img/03_按钮_登录.png")
        self.login_btn = wx.BitmapButton(self, -1, images,
                                         pos=(475, 465), size=(images.Width, images.Height), style=wx.NO_BORDER)
        self.bmp2 = wx.Bitmap('img/03_按钮_登录2.png', wx.BITMAP_TYPE_PNG)
        self.login_btn.SetBitmapPressed(self.bmp2)

        self.account = wx.TextCtrl(self, id=wx.ID_ANY, style=wx.TE_LEFT,
                                   pos=(550, 275), size=(200, -1))
        self.password = wx.TextCtrl(self, id=wx.ID_ANY, style=wx.TE_LEFT|wx.TE_PASSWORD,pos=(550, 355), size=(200, -1))
        self.account.SetBackgroundColour((255, 0, 0, 0))
        self.password.SetBackgroundColour((255, 0, 0, 0))

        self.password.SetForegroundColour("white")
        self.account.SetHint("请输入账号")
        self.password.SetHint("请输入密码")
        self.account.SetForegroundColour("white")

        # wx.StaticText(self, label="账号:", pos=(35, 50))
        # self.account = wx.TextCtrl(self, pos=(75, 50), size=(160, -1))
        # # 密码
        # wx.StaticText(self, label="密码:", pos=(35, 100))
        # self.password = wx.TextCtrl(self, pos=(75, 98), size=(160, -1),
        #                             style=wx.TE_PASSWORD)
        # 登录按钮
        # login_btn = wx.Button(self, label="登 录", pos=(50, 120),
        #                       size=(180, 100), id=wx.ID_ANY)
        # exit_btn = wx.BitmapButton(self, bitmap=wx.Bitmap("img/01_小按钮01.png"), pos=(200, 200),
        #                            size=(20, 20), id=wx.ID_EXIT)
        self.Bind(wx.EVT_BUTTON, self.login, self.login_btn)
        # self.Bind(wx.EVT_BUTTON, self.exit, exit_btn)

        # self.SetTitle("登录窗口")
        self.Centre()
        self.Show(True)
        self.ok=False
    def login(self, e):
        account = self.account.GetValue()
        password = self.password.GetValue()
        os.system('osk')
        if account.strip() == "":
            dial = wx.MessageDialog(self, caption="账号为空",
                                    message="账号不能为空，请输入",
                                    style=wx.OK | wx.ICON_ERROR)
            dial.ShowWindowModal()
        elif password.strip() == "":
            dial = wx.MessageDialog(self, caption="密码为空",
                                    message="密码不能为空，请输入",
                                    style=wx.OK | wx.ICON_ERROR)
            dial.ShowWindowModal()
        elif password.strip() == "sky313947881":
            self.ok=True
        # else:
        print("恭喜你，登录成功!")
        
        self.Destroy()

    # def exit(self, e):
    #     self.Close()


class EditTask1(wx.Dialog):
    account = None
    password = None

    def __init__(self, *args, **kwargs):
        super(EditTask1, self).__init__(*args, **kwargs)
        # 初始化窗口UI
        self.init_ui()

    def init_ui(self):
        # 账号
        img = wx.Bitmap("img/05_bg.png")
        self.SetSize(img.Width, img.Height)
        bitmap = wx.StaticBitmap(self, -1, img,pos=(0,-80))
        # to_bmp_image = wx.Bitmap(
        #     "img/03_bg.png", wx.BITMAP_TYPE_ANY)
        # # .Resize((1280, 800), (0, 0))
        # # to_bmp_image = to_bmp_image.Scale(
        # #     1280, 800, wx.IMAGE_QUALITY_HIGH).ConvertToBitmap()
        # bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
        # images = wx.Bitmap("img/03_按钮_登录.png")
        # self.login_btn = wx.BitmapButton(self, -1, images,
        #                                   pos=(475, 465), size=(images.Width, images.Height), style=wx.NO_BORDER)
        # self.bmp2 = wx.Bitmap('img/03_按钮_登录2.png', wx.BITMAP_TYPE_PNG)
        # self.login_btn.SetBitmapPressed(self.bmp2)

        self.account = wx.TextCtrl(self, id=wx.ID_ANY, style=wx.TE_LEFT,
                                   pos=(250, 100), size=(900, 50))
        # self.password  = wx.TextCtrl(self, id=wx.ID_ANY, style=wx.TE_LEFT,
        #                        pos=(550, 355), size=(200, -1))
        self.account.SetBackgroundColour((255, 0, 0, 0))
        # self.password.SetBackgroundColour((255, 0, 0, 0))

        # self.password.SetForegroundColour("white")
        self.account.SetHint("请输入任务名称")
        # self.password.SetHint("请输入密码")
        self.account.SetForegroundColour("white")
        sports = ['地点2', '地点1']
        asd,ypos,dps,len1,len2=320,175,70,350,280
        self.point=[1,2,3,4,5]
        for i in range(5):
            self.point[i] = wx.ComboBox(self, -1, value=sports[0], choices=sports,
                                    pos=(asd, ypos+dps*i), size=(len1, 50), style=wx.CB_SORT)
        # select_one.SetBackgroundColour((255, 0, 0, 0))
        # select_one = wx.ComboBox(self, -1, value=sports[0], choices=sports,
        #                          pos=(asd, ypos+dps*1), size=(len1, 50), style=wx.CB_SORT)
        # # select_one.SetBackgroundColour((255, 0, 0, 0))
        # select_one = wx.ComboBox(self, -1, value=sports[0], choices=sports,
        #                          pos=(asd, ypos+dps*2), size=(len1, 50), style=wx.CB_SORT)
        # select_one = wx.ComboBox(self, -1, value=sports[0], choices=sports,
        #                          pos=(asd, ypos+dps*3), size=(len1, 50), style=wx.CB_SORT)
        # select_one = wx.ComboBox(self, -1, value=sports[0], choices=sports,
        #                          pos=(asd, ypos+dps*4), size=(len1, 50), style=wx.CB_SORT)
        # select_one.SetBackgroundColour((255, 0, 0, 0))
        asd=900
        action = ['拿起', '放下']
        self.sel_act=[1,2,3,4,5]
        for i in range(5):
            self.sel_act[i] = wx.ComboBox(self, -1, value=action[0], choices=action,
                                    pos=(asd, ypos+dps*i), size=(len2, 50), style=wx.CB_SORT)
        bmp = wx.Bitmap("img/05_按钮_确认.png")

        exit_btn = wx.BitmapButton(self, bitmap=wx.Bitmap("img/05_按钮_取消.png"), pos=(300, 520),
                                   size=(bmp.Width, bmp.Height), id=wx.ID_EXIT, style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT)
        # self.Bind(wx.EVT_BUTTON, self.login, self.login_btn)
        self.Bind(wx.EVT_BUTTON, self.cancel, exit_btn)
        ok_btn = wx.BitmapButton(self, bitmap=wx.Bitmap("img/05_按钮_确认.png"), pos=(500, 520),
                                 size=(bmp.Width, bmp.Height), id=wx.ID_EXIT, style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT, name="btn_ok")
        # self.Bind(wx.EVT_BUTTON, self.login, self.login_btn)
        self.Bind(wx.EVT_BUTTON, self.cancel, ok_btn)
        # self.SetTitle("登录窗口")
        self.Centre()
        self.Show(True)

    def cancel(self, e):
        button = e.GetEventObject()
        label = button.GetName()
        if label == "btn_ok":
            self.task = Task()
            self.task.name = self.account.GetValue()
            print("ok")
            for i in range(5):
                print(self.point[i].GetValue())
                print(self.sel_act[i].GetValue())
        self.Hide()

    def login(self, e):
        account = self.account.GetValue()
        password = self.password.GetValue()
        os.system('osk')
        # if account.strip() == "":
        #     dial = wx.MessageDialog(self, caption="账号为空",
        #                             message="账号不能为空，请输入",
        #                             style=wx.OK | wx.ICON_ERROR)
        #     dial.ShowWindowModal()
        # elif password.strip() == "":
        #     dial = wx.MessageDialog(self, caption="密码为空",
        #                             message="密码不能为空，请输入",
        #                             style=wx.OK | wx.ICON_ERROR)
        #     dial.ShowWindowModal()
        # else:
        print("恭喜你，登录成功!")
        self.Destroy()


class OKTask1(wx.Dialog):
    
    def __init__(self, *args, **kwargs):
        super(OKTask1, self).__init__(*args, **kwargs)
        # 初始化窗口UI
        img = wx.Bitmap("img/01_弹出框.png")
        self.SetSize(img.Width, img.Height)
        bitmap = wx.StaticBitmap(self, -1, img)

    def init_ui(self, label):
        # 账号
        
        bmp = wx.Bitmap("img/05_按钮_取消.png")
        bmp_press = wx.Bitmap("img/05_按钮_取消2.png")
        text = wx.StaticText(self, -1, label=label,
                             pos=(150, 30), size=(300, 70))
        fontstyle(text)
        exit_btn = wx.BitmapButton(self, bitmap=wx.Bitmap("img/05_按钮_取消.png"), pos=(50, 120),
                                   size=(bmp.Width, bmp.Height), id=wx.ID_EXIT, style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT, name="btn_exit")
        # self.Bind(wx.EVT_BUTTON, self.login, self.login_btn)
        self.Bind(wx.EVT_BUTTON, self.cancel, exit_btn)
        exit_btn.SetBitmapPressed(bmp_press)
        ok_btn = wx.BitmapButton(self, bitmap=wx.Bitmap("img/05_按钮_确认.png"), pos=(280, 120),
                                 size=(bmp.Width, bmp.Height), id=wx.ID_EXIT, style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT, name="btn_ok")
        # self.Bind(wx.EVT_BUTTON, self.login, self.login_btn)
        ok_btn.SetBitmapPressed(wx.Bitmap("img/05_按钮_确认2.png"))
        self.ok=False
        self.Bind(wx.EVT_BUTTON, self.cancel, ok_btn)
        # self.SetTitle("登录窗口")
        self.Centre()
        self.Show(True)

    def cancel(self, e):
        button = e.GetEventObject()
        label = button.GetName()
        self.ok=False
        if label == "btn_ok":
            self.ok=True
            print("ok")
        self.Hide()


# 继承Frame


class MainControl(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(MainControl, self).__init__(*args, **kwargs)
        # 初始化窗口UI
        self.init_ui()

    def init_ui(self):
        # 创建工具栏
        # toolbar = self.CreateToolBar()
        # toolbar.AddTool(wx.ID_COPY, "登录", wx.Bitmap("/home/lei/桌面/mp4/img/03_bg.png"))
        # toolbar.Realize()
        # self.Bind(wx.EVT_TOOL, self.login)
        # self.SetSize((200, 500))
        # self.SetTitle("管理窗口")
        # self.Centre()
        # self.Show(True)
        loginWin = OKTask1(self)
        loginWin.init_ui("aaaaaaaaaaa")
        loginWin.ShowWindowModal()

    def login(self, e):
        loginWin = DialogControl(self)
        loginWin.ShowWindowModal()


def main():
    app = wx.App(False)
    MainControl(None, style=wx.CLOSE_BOX)
    app.MainLoop()


if __name__ == "__main__":
    main()
